//
//  YZCommunityLocationCell.m
//  VET
//
//  Created by YZ on 2018/7/11.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZCommunityLocationCell.h"

@interface YZCommunityLocationCell()

@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UILabel *subTitleLb;

@property (nonatomic, strong) UIImageView *iconImgView;

@end

@implementation YZCommunityLocationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.layer.masksToBounds = YES;
        self.backgroundColor = kColorWithHex(0xFFFFFF);
        [self.contentView addSubview:self.titleLb];
        [self.contentView addSubview:self.subTitleLb];
        [self.contentView addSubview:self.iconImgView];
        
        [self makeContraints];
    }
    return self;
}

- (void)makeContraints
{
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kCurrentDeviceNum(20));
        make.top.mas_equalTo(kCurrentDeviceNum(10));
        make.width.mas_lessThanOrEqualTo(200);
    }];
    
    [self.subTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLb);
        make.top.equalTo(self.titleLb.mas_bottom);
        make.width.mas_lessThanOrEqualTo(300);
        make.bottom.equalTo(self.contentView).offset(-kCurrentDeviceNum(5));
    }];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-kCurrentDeviceNum(10));
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(kCurrentDeviceNum(16), kCurrentDeviceNum(16)));
    }];
}

#pragma mark -- setters && getters

- (UILabel *)titleLb
{
    if(!_titleLb){
        _titleLb = [UILabel new];
        _titleLb.textAlignment = NSTextAlignmentLeft;
        _titleLb.font = kCurrentDeviceFont(16);
        _titleLb.textColor = kColorWithHex(0x393939);
    }
    return _titleLb;
}

- (UILabel *)subTitleLb
{
    if(!_subTitleLb){
        _subTitleLb = [UILabel new];
        _subTitleLb.textAlignment = NSTextAlignmentLeft;
        _subTitleLb.font = kCurrentDeviceFont(12);
        _subTitleLb.textColor = kColorWithHex(0x9B9B9B);
    }
    return _subTitleLb;
}

- (UIImageView *)iconImgView
{
    if(!_iconImgView){
        _iconImgView = [UIImageView new];
        _iconImgView.image = [UIImage imageNamed:@"ico_itemselect"];
        _iconImgView.hidden = YES;
    }
    return _iconImgView;
}

- (void)setModel:(YZCommunityLocationModel *)model
{
    _model = model;
    self.titleLb.text = model.addressName;
    self.subTitleLb.text = model.address;
    self.iconImgView.hidden = !model.selected;
}
@end
